<div class="bjui-pageContent">
    <div style="padding-top:20px;">
        <div class="clearfix">
            <div style="float:left; width:220px; height:100%; overflow:auto;">
                <ul id="appMenuTree" class="ztree" data-toggle="ztree"  >
                </ul>
            </div>
            <div id="appMenuTree-detail" style="margin-left:220px; width:420px; height:100%;">
                <form action="#" id="appMenuForm">
                	<input type="hidden" name="appcfgId">
                	<input type="hidden" name="id">
                	<input type="hidden" name="pid">
                	<input type="hidden" name="mLevel">
                    <div class="form-group">
                        <label for="appMenu_name" class="control-label x85">NAME：</label>
                        <input type="text" class="form-control" data-rule="required" name="name" id="appMenu_name" size="20" />
                    </div>
                    <div class="form-group">
                        <label for="appMenu_key" class="control-label x85">KEY：</label>
                        <input type="text" class="form-control" name="key" id="appMenu_key" size="20" />
                    </div>
                    <div class="form-group">
                        <label for="appMenu_type" class="control-label x85">TYPE：</label>
                        <input type="text" class="form-control" data-rule="required" name="type" id="appMenu_type" size="20" />
                    </div>
                    <div class="form-group">
                        <label for="appMenu_url" class="control-label x85">URL：</label>
                        <input type="text" class="form-control" name="url" id="appMenu_url" size="20" />
                    </div>
                    <div class="form-group">
                        <label for="appMenu_oauth" class="control-label x85">网页授权：</label>
                        <input type="radio" name="oauth" id="oauth1" data-toggle="icheck" value="T"  data-label="<span style='color:red;'>是</span>">
                        &nbsp;&nbsp;
                        <input type="radio" name="oauth" id="oauth2" data-toggle="icheck" value="F" checked data-label="否">
                    </div>
                    <div class="form-group">
                        <label for="appMenu_orderid" class="control-label x85">排序ID：</label>
                        <input type="text" class="form-control" data-rule="required" name="orderId" id="appMenu_orderid" size="20" />
                    </div>
                    <div class="form-group" style="padding-top:8px; border-top:1px #DDD solid;text-align:center;">
                        <a class="btn btn-green" onclick="appMenuSave();">保存</a>
                        <a class="btn btn-red" onclick="appMenuDel();">删除</a>
                        <a class="btn btn-green" onclick="appMenuTreeAddNode(1);">添加一级菜单</a>
                        <a class="btn btn-green" onclick="appMenuTreeAddNode(2);">添加二级菜单</a>
                        <div style="margin-top:8px;text-align:left">
                        <i class="fa fa-warning" style="color:red"></i> 
                        	注意：<br>
                        	1、排序ID，值越小越排在前面。<br>
                        	2、不能删除拥有子菜单的菜单。<br>
                        	3、Type类型：click-点击推事件、view-跳转URL、scancode_push-扫码推事件，等<br>
                        	4、是否网页授权，是则将在构建菜单时将URL转换成授权的回调链接<br/>
                        	5、微信菜单目前支持一级菜单3个，二级菜单5个，即支持15个菜单
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>
<!-- 菜单管理 -->
<script type="text/javascript">
//初始化菜单树
function initAppMenuTree(appcfgId){
	//获取appid对应的菜单
	var treeData = ajaxJsonSync("weixin/basedata/appMenuButtonMgr",{action:"menuTree",appcfgId:appcfgId});
	var setting = {
		callback:{
			onClick:onAppMenuTreeClick
		},
		data: {
			simpleData: {
				enable: true,
				idKey: "id",
				pIdKey: "pId",
				rootPId: null
			}
		}
	};
	$.fn.zTree.init($.CurrentNavtab.find("#appMenuTree"), setting, treeData);
}

function onAppMenuTreeClick(event, treeId, treeNode) {
	var id = treeNode.id;
	if(id!=null){
		//从后台获取菜单信息
		var data = ajaxJsonSync("weixin/basedata/appMenuButtonMgr",{action:"get",id:id});
		setFormData("#appMenuForm",data);
	}else{
		setFormData("#appMenuForm",treeNode);
	}
};

function appMenuTreeAddNode(mLevel){
	var id = $.CurrentNavtab.find("#id").val();
	if(id==null||id==""){
		$(this).alertmsg("warn","请选择要操作的配置项！");
		return;
	}
	var zTree = $.fn.zTree.getZTreeObj("appMenuTree");
	if("1"==mLevel){
		//添加一级菜单
		//添加节点到菜单树上
		 var new_node = {name:"一级菜单（新增）",appcfgId:id,mLevel:1};
		 new_node = zTree.addNodes(null,new_node,false);
	}else if("2"==mLevel){
		//添加二级菜单
		var node = zTree.getSelectedNodes()[0];
		if(node&&node.id!=null){
			var new_node = {name:"二级菜单（新增）",appcfgId:id,mLevel:2,pid:node.id};
			new_node = zTree.addNodes(node,new_node,false);
		}else{
			$(this).alertmsg("warn","请选择节点或保存新增菜单节点！");
		}
	}
}

function appMenuSave(){
	//获取表单数据
	var data = getFormData("#appMenuForm");
	if(data==null||data.appcfgId==""){
		$(this).alertmsg("warn","请选择要操作的菜单项！");
		return;
	}
	var done = ajaxJsonSync("weixin/basedata/appMenuButtonMgr",{action:"save",menuInfo:JSON.stringify(data)});
	//提示
	ajaxDoneTip(done);
	//更新节点数信息
	var zTree = $.fn.zTree.getZTreeObj("appMenuTree");
	var node = zTree.getSelectedNodes()[0];
	node.name=data.name;
	node.id=done.data;
	zTree.updateNode(node);
}

function appMenuDel(){
	//获取表单数据
	var data = getFormData("#appMenuForm");
	if(data==null||data.id==""){
		$(this).alertmsg("warn","请选择要删除的菜单项！");
		return;
	}
	var result = ajaxJsonSync("weixin/basedata/appMenuButtonMgr",{action:"del",id:data.id});
	actionResultTip(result);
	//更新节点数信息
	var zTree = $.fn.zTree.getZTreeObj("appMenuTree");
	var node = zTree.getNodesByParam("id",data.id,null);
	zTree.removeNode(node[0]);
	setFormData("#appMenuForm",{});
}
</script>